home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
sticpsrc.lzh
/
SOURCE.ARC
/
SMISC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-02-06
|
4KB
|
193 lines
/* Miscellaneous servers */
#include <stdio.h>
#include "global.h"
#include "mbuf.h"
#include "netuser.h"
#include "timer.h"
#include "tcp.h"
#include "remote.h"
static struct tcb *disc_tcb,*echo_tcb;
static struct socket remsock;
/* Start up discard server */
dis1(argc,argv)
int argc;
char *argv[];
{
struct socket lsocket;
void disc_recv(),misc_state();
char tos = 0;
lsocket.address = ip_addr;
if(argc < 2)
lsocket.port = DISCARD_PORT;
else {
if ((lsocket.port = atoi(argv[1])) == 0)
lsocket.port = DISCARD_PORT;
tos = get_tos(argv[2]);
}
disc_tcb = open_tcp(&lsocket,NULLSOCK,TCP_SERVER,0,disc_recv,NULLVFP,misc_state,tos,(char *)NULL);
return 0;
}
/* Start echo server */
echo1(argc,argv)
int argc;
char *argv[];
{
void echo_recv(),echo_trans(),misc_state();
struct socket lsocket;
char tos = 0;
lsocket.address = ip_addr;
if(argc < 2)
lsocket.port = ECHO_PORT;
else {
if ((lsocket.port = atoi(argv[1])) == 0)
lsocket.port = ECHO_PORT;
tos = get_tos(argv[2]);
}
echo_tcb = open_tcp(&lsocket,NULLSOCK,TCP_SERVER,0,echo_recv,echo_trans,misc_state,tos,(char *)NULL);
return 0;
}
/* Start remote exit/reboot server */
rem1(argc,argv)
int argc;
char *argv[];
{
void uremote();
remsock.address = ip_addr;
if(argc < 2)
remsock.port = REMOTE_PORT;
else
remsock.port = atoi(argv[1]);
open_udp(&remsock,uremote);
return 0;
}
/* Shut down miscellaneous servers */
dis0()
{
if(disc_tcb != NULLTCB)
close_tcp(disc_tcb);
return 0;
}
echo0()
{
if(echo_tcb != NULLTCB)
close_tcp(echo_tcb);
return 0;
}
rem0()
{
del_udp(&remsock);
return 0;
}
/* Discard server receiver upcall */
static
void
disc_recv(tcb,cnt)
struct tcb *tcb;
int16 cnt;
{
struct mbuf *bp;
if(recv_tcp(tcb,&bp,cnt) > 0)
free_p(bp); /* Discard */
}
/* Echo server receive
* Copies only as much will fit on the transmit queue
*/
static
void
echo_recv(tcb,cnt)
struct tcb *tcb;
int cnt;
{
struct mbuf *bp;
int acnt;
if(cnt == 0){
close_tcp(tcb);
return;
}
acnt = min(cnt,tcb->snd.wnd);
if(acnt > 0){
/* Get only as much will fit in the send window */
recv_tcp(tcb,&bp,tcb->snd.wnd);
send_tcp(tcb,bp);
}
}
/* Echo server transmit
* Copies anything that might have been left in the receiver queue
*/
static
void
echo_trans(tcb,cnt)
struct tcb *tcb;
int16 cnt;
{
struct mbuf *bp;
if(tcb->rcvcnt > 0){
/* Get only as much will fit in the send window */
recv_tcp(tcb,&bp,cnt);
send_tcp(tcb,bp);
}
}
/* Log connection state changes; also respond to remote closes */
static
void
misc_state(tcb,old,new)
register struct tcb *tcb;
char old,new;
{
switch(new){
case ESTABLISHED:
log_tcp(tcb,"open %d",tcb->conn.local.port);
break;
case CLOSE_WAIT:
close_tcp(tcb);
break;
case CLOSED:
log_tcp(tcb,"close %d",tcb->conn.local.port);
del_tcp(tcb);
/* Clean up if server is being shut down */
if(tcb == disc_tcb)
disc_tcb = NULLTCB;
else if(tcb == echo_tcb)
echo_tcb = NULLTCB;
break;
}
}
/* Process remote exit/reset command */
void
uremote(sock,cnt)
struct socket *sock;
int16 cnt;
{
struct mbuf *bp;
struct socket fsock;
char command;
recv_udp(sock,&fsock,&bp);
command = pullchar(&bp);
switch(uchar(command)){
#if (defined(MSDOS) || defined(ATARI_ST))
case SYS_RESET:
log_msg("%s - REMOTE RESET",psocket(&fsock));
doexit(-1);
sysreset();
break; /* Not necessary */
#endif
case SYS_EXIT:
log_msg("%s - REMOTE EXIT",psocket(&fsock));
doexit(0);
break;
}
}